<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="css/layui.css" media="all">
</head>
<body>
	<form class="layui-form" onsubmit="return false">
		<div class="layui-inline">
			<label class="layui-form-label">编号:</label>
			<div class="layui-input-block">
				<input type="text" name="id" id="id" 
					autocomplete="off" placeholder="请输入..." class="layui-input" readonly>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">部门:</label>
			<div class="layui-input-block">
				<input type="text" name="dname" id="dname"
					autocomplete="off" placeholder="请输入..." class="layui-input">
			</div>
		</div>
		<br> <br> <br>
		<div class="layui-inline">
			<label class="layui-form-label">地址:</label>
			<div class="layui-input-block">
				<input type="text" name="dloc"  autocomplete="off" id="dloc"
					placeholder="请输入..." class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" 
					>立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="layui.js"></script>
	<script type="text/javascript" src="lay/jquery.min.js"></script>
	<script type="text/javascript">
	String.prototype.getParameter = function (key) {  
	    var re = new RegExp(key + '=([^&]*)(?:&)?');  
	    return this.match(re) && this.match(re)[1];  
	}; 
	function getParamterByKey(key) {
		   return location.href.getParameter(key); 
		}
	$(function() {
		$.post(
				"department?opr=selectId",
				"id="+getParamterByKey("id"),
				function(data) {
					if (data) {
						$("#id").val(data.data[0].id);
						$("#dname").val(data.data[0].dname);
						$("#dloc").val(data.data[0].dloc);
					}
				},
				"json"
				);
		$(".layui-form").submit(function() {		
			$.post(
					"department?opr=update",
					$(this).serialize(),
					function(data) {
						if (data.success) {
							  layer.msg("修改成功");
						} else {
							  layer.msg("修改失败");
						}
					}
			)
			})
	});
	</script>
</body>
</html>